package com.photoeditor.demo.ui.fragement.gallery;

import android.Manifest;
import android.app.ProgressDialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.photoeditor.R;
import com.photoeditor.demo.app.XFragment;
import com.photoeditor.demo.model.bean.DateBean;
import com.photoeditor.demo.model.bean.ThumbnailBean;
import com.photoeditor.demo.model.image.util.ImageHelper;
import com.photoeditor.demo.model.share.ShareImageTools;
import com.photoeditor.demo.ui.activity.GalleryActivity;
import com.photoeditor.demo.ui.activity.edit.ImagePreviewActivity;
import com.photoeditor.demo.ui.adapter.gallery.ICheckedChangeListener;
import com.photoeditor.demo.ui.adapter.gallery.IFaceDetectListener;
import com.photoeditor.demo.ui.adapter.gallery.IOnFragmentChange;
import com.photoeditor.demo.ui.adapter.gallery.ListGridAdapter;
import com.photoeditor.demo.ui.adapter.share.ShareImageListAdapter;
import com.photoeditor.demo.ui.widget.gallery.GalleryRowItem;
import com.photoeditor.demo.ui.widget.share.ShareImageItem;
import com.photoeditor.demo.ui.widget.share.ShareImageItem.ShareImageItemData;
import com.photoeditor.demo.util.ArrayUtil;
import com.photoeditor.demo.util.AsyncTask;
import com.photoeditor.demo.util.IDeleteListener;
import com.photoeditor.demo.util.PermissionUtil;

import java.util.ArrayList;
import java.util.LinkedHashMap;

public class GalleryFragment extends XFragment implements IFaceDetectListener {
    /*
     * 用于存储图片的URL
     */
    private ArrayList<ThumbnailBean> mUris;

    /**
     * 主列表
     */
    private ListView mListView;

    private ListGridAdapter mAdapter;

    private DateBean mNowTime;

    private ProgressDialog mProgressDialog;

    /**
     * 删除时的验证Dialog
     */
    private AlertDialog mDeleteConfirmDialog;

    /**
     * 移入私密箱时的验证Dialog
     */
    private AlertDialog mPrivateConfirmDialog;

    private GalleryActivity mActivity;

    private View mContainerView;

    /**
     * 分享相关
     */
    private View mShade;
    private View mSharePanel;
    private GridView mShareImageView;
    private ShareImageListAdapter mShareImageAdapter;

    //空的时候的界面
    private View mEmptyGalleryView;

    public static final int COL_NUM = 3;

    private IFaceDetectListener mLoadingListener;

    private String mEntrance;

    public GalleryFragment(ICheckedChangeListener listener, IOnFragmentChange dataListener, IFaceDetectListener dListener) {
        mActivityListener = listener;
        mDataListener = dataListener;
        mLoadingListener = dListener;
    }

    public GalleryFragment() {

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = (GalleryActivity) getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View contanerView = inflater.inflate(R.layout.fragment_gallery, container, false);
        initView(contanerView);
        isCreated = true;
        setNeedRefresh(true);
        loadGridFlowAd();
        if (mDataListener != null) {
            mDataListener.onFragmentCreated(GalleryActivity.TYPE_FRAGMENT_GALLERY);
        }
        if (getArguments() != null) {
            mEntrance = getArguments().getString("fromWhere");
        }
        return contanerView;
    }

    @Override
    public void startDetect() {
        mLoadingListener.startDetect();
    }

    @Override
    public void endDetect() {
        mLoadingListener.endDetect();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (isAdded()) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (mSharePanel != null && mSharePanel.getVisibility() == View.VISIBLE) {
                    mSharePanel.setVisibility(View.GONE);
                    mShade.setVisibility(View.GONE);
                    return true;
                }
                if (mAdapter != null && mAdapter.isCheckStatus()) {
                    mActivity.doCancel(mAdapter);
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public void onNewIntent(Intent intent) {

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == GalleryActivity.REQUEST_CODE_PREVIEW) {
            if (data != null) {
                int refresh = data.getIntExtra(ImagePreviewActivity.NEED_RESFREH, ImagePreviewActivity.REFRESH_NONE);
                if (refresh == ImagePreviewActivity.REFRESH_CURRENT) {
                    setNeedRefresh(true);
                    refreshData();
                } else if (refresh == ImagePreviewActivity.REFRESH_ALL) {
                    setNeedRefresh(true);
                    refreshData();
                    if (mDataListener != null) {
                        mDataListener.onDataChange(GalleryActivity.TYPE_FRAGMENT_OTHER_GALLERY);
                    }
                } else if (refresh == ImagePreviewActivity.REFRESH_CURRENT_AND_OTHER_GALLERY) {
                    setNeedRefresh(true);
                    refreshData();
                    if (mDataListener != null) {
                        mDataListener.onDataChange(GalleryActivity.TYPE_FRAGMENT_OTHER_GALLERY);
                    }
                }
            }
        }
    }

    private void initView(View contanerView) {
        mContainerView = contanerView;
        mListView = (ListView) contanerView.findViewById(R.id.list);
        mShade = contanerView.findViewById(R.id.shade);
        initPermissionView();
    }

    private void initPermissionView() {
        if (PermissionUtil.needRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            mContainerView.findViewById(R.id.layoutPermission).setVisibility(View.VISIBLE);
            mContainerView.findViewById(R.id.tvRequestPermission).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mActivity.handlePermission();
                }
            });
        } else {
            if (mContainerView.findViewById(R.id.layoutPermission).getVisibility() == View.VISIBLE) {
                mContainerView.findViewById(R.id.layoutPermission).setVisibility(View.GONE);
            }
        }
    }

    private void hidePermissionView() {
        if (!PermissionUtil.needRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            if (mContainerView.findViewById(R.id.layoutPermission).getVisibility() == View.VISIBLE) {
                mContainerView.findViewById(R.id.layoutPermission).setVisibility(View.GONE);
            }
        }
    }

    /**
     * 分享界面初始化
     */
    private void initShareImageView() {
        if (mSharePanel == null) {
            ViewStub vs = (ViewStub) mContainerView.findViewById(R.id.share_iamge_viewstub_id);
            if (vs == null) {
                mSharePanel = mContainerView.findViewById(R.id.share_iamge_layout_id);
            } else {
                mSharePanel = vs.inflate();
            }
            mShareImageView = (GridView) mSharePanel.findViewById(R.id.share_gridview);
            LinearLayout.LayoutParams param = (LinearLayout.LayoutParams) mShareImageView.getLayoutParams();
            param.height = ImageHelper.SCREEN_HEIGHT * 2 / 3 - mActivity.getResources().getDimensionPixelSize(R.dimen.share_textview_height);
            mShareImageView.setLayoutParams(param);
            mShareImageView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    if (arg1 instanceof ShareImageItem) {
                        ShareImageItem flag = (ShareImageItem) arg1;
                        ShareImageItemData siid = flag.getItemData();
                        boolean isInstall = ShareImageTools.getAppIsInstalled(mActivity, siid.getmPkgName());
                        if (isInstall) {
                            boolean result = ShareImageTools.startCommonShareMutilMediaActivity(mActivity,
                                    siid.getmPkgName(), siid.getmActivityName(), getSelectedData(), mActivity.getCheckedImageNum(), mActivity.getCheckedVideoNum());
                            mAdapter.setCheckStatus(false);
                            mSharePanel.setVisibility(View.GONE);
                            mShade.setVisibility(View.GONE);
                            if (!result) {
                                Toast.makeText(mActivity, R.string.not_install, Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(mActivity, R.string.not_install, Toast.LENGTH_SHORT).show();
                        }

                        String activityName = flag.getItemData().getmActivityName();
                    }
                }

            });
            mShade.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    mSharePanel.setVisibility(View.GONE);
                    mShade.setVisibility(View.GONE);
                    return true;
                }
            });
        }
        mSharePanel.setVisibility(View.VISIBLE);
        mShade.setVisibility(View.VISIBLE);
    }

    /**
     * 初始化分享的Adapter
     */
    private void initShareImageViewAdapter(int imageNum, int videoNum) {
        if (mShareImageAdapter == null) {
            mShareImageAdapter = new ShareImageListAdapter(mActivity, ShareImageTools.getAllShareMutilMediaTools(mActivity, imageNum, videoNum));
            mShareImageView.setAdapter(mShareImageAdapter);
        } else {
            mShareImageAdapter.setData(ShareImageTools.getAllShareMutilMediaTools(mActivity, imageNum, videoNum));
            mShareImageAdapter.notifyDataSetChanged();
        }
    }

    private ArrayList<Uri> getSelectedData() {
        ArrayList<ThumbnailBean> checkedList = mAdapter.getCheckedList();
        int len = checkedList.size();
        ArrayList<Uri> result = new ArrayList<Uri>(len);
        for (int i = 0; i < len; i++) {
            result.add(checkedList.get(i).getUri());
        }
        return result;
    }

    @Override
    public void setNeedRefresh(boolean flag) {
        isNeedRefresh = flag;
    }

    @Override
    public void refreshData() {
        if (PermissionUtil.needRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            return;
        }
        if ((mAdapter == null || isNeedRefresh) && isCreated) {
            setNeedRefresh(false);
            getGettingDataTask().executeOnExecutor(AsyncTask.DATABASE_THREAD_EXECUTOR, null, mActivity.getParams());
        }
    }

    @Override
    public void forceRefreshData() {
        if (PermissionUtil.needRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            return;
        }
        if (mActivity == null) {
            return;
        }
        setNeedRefresh(false);
        getGettingDataTask().executeOnExecutor(AsyncTask.DATABASE_THREAD_EXECUTOR, null, mActivity.getParams());
    }

    /**
     * 获取数据的异步任务
     *
     * @return
     */
    public AsyncTask<String, Integer, ArrayList<ThumbnailBean>> getGettingDataTask() {
        AsyncTask<String, Integer, ArrayList<ThumbnailBean>> mGetDataTask = new AsyncTask<String, Integer, ArrayList<ThumbnailBean>>() {

            @Override
            protected ArrayList<ThumbnailBean> doInBackground(String... params) {
                ArrayList<ThumbnailBean> datas = null;
                int isNeedDeal = Integer.valueOf(params[1]);
                if (isNeedDeal == 0) {//all
//					if (mActivity != null && mActivity.isPickToCollageMode()) {
//						// 拼图显示视频时长最大为30s
//						datas = ImageHelper.getThumbnailBeanFromPath(mActivity, params[0], 30 * 1000);
//					} else {
                    datas = ImageHelper.getThumbnailBeanFromPath(mActivity, params[0]);
//					}
                } else if (isNeedDeal == 1) {//代表Image + gif
                    datas = ImageHelper.getImageThumbnailBeanFromPath(mActivity, params[0]);
                } else if (isNeedDeal == 2) {//代表Video
                    datas = ImageHelper.getVideoThumbnailBeanFromPath(mActivity, params[0]);
                } else if (isNeedDeal == 3) {//代表Image + 动态图片（其实是视频）
                    datas = ImageHelper.getImageAndDynamicThumbnailBeanFromPath(mActivity, params[0]);
                } else if (isNeedDeal == 4) {// 仅图片不包含gif
                    datas = ImageHelper.getImageThumbnailBeanFromPathExcludeGif(mActivity, params[0]);
                }
                addCamera(datas);
                return datas;
            }

            @Override
            protected void onPostExecute(ArrayList<ThumbnailBean> result) {
                if (result == null || result.size() == 0) {//做一个保护
//					Toast.makeText(mActivity, R.string.no_pictures, Toast.LENGTH_SHORT).show();
//					mActivity.finish();
                    if (mContainerView.findViewById(R.id.layoutPermission).getVisibility() == View.GONE)
                        getEmptyGalleryView().setVisibility(View.VISIBLE);
                    return;
                }
                if (mEmptyGalleryView != null) {
                    mEmptyGalleryView.setVisibility(View.GONE);
                }
                mUris = result;
                LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(5, 1f, false);
                if (mNowTime == null) {
                    mNowTime = new DateBean();
                }
                ArrayList<Object> datas = mActivity.uniformData(result, map, mNowTime, COL_NUM);
                if (mAdapter == null) {
                    mAdapter = new ListGridAdapter(datas, map, COL_NUM, mActivity, mNowTime.getDateTime());
                    if (!TextUtils.isEmpty(mEntrance)) {
                        mAdapter.setFromWhere(mEntrance);
                    }
                    mAdapter.setOnCheckedChangeListener(mActivityListener);
                } else {
                    mAdapter.setData(datas, map, mNowTime.getDateTime());
                }
                if (mListView != null) {
                    mListView.setAdapter(mAdapter);
                }
                hidePermissionView();
            }
        };
        return mGetDataTask;
    }

    private void addCamera(ArrayList<ThumbnailBean> datas) {
        if (datas == null) {
            datas = new ArrayList<ThumbnailBean>();
        }
        datas.add(0, new ThumbnailBean("open_camera", System.currentTimeMillis(), false, getUriFromDrawableRes(mActivity, R.drawable.icon_camera), 90, 3));
    }

    public Uri getUriFromDrawableRes(Context context, int id) {
        if (context == null) {
            return Uri.parse("");
        }
        Resources resources = context.getResources();
        String path = ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
                + resources.getResourcePackageName(id) + "/"
                + resources.getResourceTypeName(id) + "/"
                + resources.getResourceEntryName(id);
        return Uri.parse(path);
    }


    public void showDeleteConfirmDialog() {
        if (mDeleteConfirmDialog == null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
            builder.setTitle(R.string.tip);
            builder.setMessage(R.string.gallery_delete_dialog_message);
            builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    mDeleteConfirmDialog.dismiss();
                }
            });
            builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    doDelete();
                    mDeleteConfirmDialog.dismiss();
                }
            });
            mDeleteConfirmDialog = builder.create();
            mDeleteConfirmDialog.setCancelable(true);
            mDeleteConfirmDialog.setCanceledOnTouchOutside(false);
            mDeleteConfirmDialog.show();
        } else {
            mDeleteConfirmDialog.show();
        }
    }

    /**
     * 处理点击delete
     */
    private void doDelete() {
        final ArrayList<ThumbnailBean> checkedList = mAdapter.getCheckedList();
        final int len = checkedList.size();
        if (len != 0) {
            new AsyncTask<Void, Integer, ArrayList<ThumbnailBean>>() {
                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    if (mProgressDialog == null) {
                        mProgressDialog = new ProgressDialog(mActivity, ProgressDialog.THEME_HOLO_LIGHT);
                        mProgressDialog.setCancelable(false);
                        mProgressDialog.setCanceledOnTouchOutside(false);
                        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                        mProgressDialog.setMax(checkedList.size());
                        mProgressDialog.setTitle(R.string.doing_delete);
                        mProgressDialog.setProgress(0);
                        mProgressDialog.show();
                    } else {
                        dismissProgressDialog();
                        mProgressDialog.setTitle(R.string.doing_delete);
                        mProgressDialog.setMax(checkedList.size());
                        mProgressDialog.show();
                        mProgressDialog.setProgress(0);
                    }
                }

                @Override
                protected void onProgressUpdate(Integer... values) {
                    mProgressDialog.setProgress(mProgressDialog.getProgress() + values[0].intValue());
                    super.onProgressUpdate(values);
                }

                @Override
                protected ArrayList<ThumbnailBean> doInBackground(Void... params) {
//					int l = checkedList.size();
//					for(int i = 0 ; i < l ; i++){
//						ThumbnailBean thumbnailBean = checkedList.get(i);
//						ImageHelper.deleteMediaByUri(mActivity, thumbnailBean.getUri(), thumbnailBean.getPath());
//						publishProgress(i + 1);
//					}
                    final ArrayList<ThumbnailBean> deleteSuccessList = new ArrayList<ThumbnailBean>();
                    ImageHelper.deleteMedia(mActivity, ArrayUtil.copyArray(checkedList), new IDeleteListener<ThumbnailBean>() {
                        @Override
                        public void onDeleteFile(ThumbnailBean bean, boolean success) {
                            publishProgress(1);
                            if (success) {
                                deleteSuccessList.add(bean);
                            }
                        }

                        @Override
                        public void onDeleteFiles(boolean success) {//在这里不存在这种情况

                        }
                    }, true);
                    return deleteSuccessList;
                }

                @Override
                protected void onPostExecute(ArrayList<ThumbnailBean> result) {
                    dismissProgressDialog();
                    if (result.size() == len) {
                        Toast.makeText(mActivity, R.string.delete_success, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(mActivity, R.string.delete_fail, Toast.LENGTH_SHORT).show();
                    }

                    if (mDataListener != null) {
                        mDataListener.onDataChange(GalleryActivity.TYPE_FRAGMENT_OTHER_GALLERY);
                    }

                    mUris.removeAll(result);
                    if (mUris.size() == 0) {
                        if (mContainerView.findViewById(R.id.layoutPermission).getVisibility() == View.GONE)
                            getEmptyGalleryView().setVisibility(View.VISIBLE);
                    }
                    mAdapter.restoreCheckedList();
                    LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(5, 1f, false);
                    if (mNowTime == null) {
                        mNowTime = new DateBean();
                    }
                    ArrayList<Object> datas = mActivity.uniformData(mUris, map, mNowTime, COL_NUM);
                    mAdapter.setData(datas, map, mNowTime.getDateTime());
                    mAdapter.setCheckStatus(false);
                    super.onPostExecute(result);
                }
            }.executeOnExecutor(AsyncTask.DATABASE_THREAD_EXECUTOR);

        }
    }

    public int getPosition(ThumbnailBean bean) {
        return mUris.indexOf(bean);
    }

    @Override
    public void startImagePreviewActivity(ThumbnailBean bean, int requestCode) {
        if (bean != null && mUris != null) {
            Intent i = new Intent(mActivity, ImagePreviewActivity.class);
            i.putExtra(ImagePreviewActivity.ENTRANCE, ImagePreviewActivity.FROM_GALLERY);
            int position = getPosition(bean);
            i.putExtra(ImagePreviewActivity.POSITION, position);
            mActivity.startActivityForResult(i, requestCode);
			/*if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
				ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(mActivity);
				mActivity.startActivityForResult(i, requestCode, transitionActivityOptions.toBundle());
			} else{
				mActivity.startActivityForResult(i, requestCode);
//				mActivity.overridePendingTransition(R.anim.activity_bottom_in, 0);
			}*/
        }
    }

    @Override
    public ListGridAdapter getAdapter() {
        return mAdapter;
    }

    @Override
    public void doOnStart() {
        if (isAdded()) {
            refreshData();
        }
    }


    @Override
    public void onMoveClick(View v) {
    }

    @Override
    public boolean onBackClick(View v) {
        return false;
    }

    @Override
    public void onCancelClick(View v) {
        if (mSharePanel != null && mSharePanel.getVisibility() == View.VISIBLE) {
            mSharePanel.setVisibility(View.GONE);
            mShade.setVisibility(View.GONE);
        }
        if (mAdapter != null) {
            if (mAdapter.isCheckStatus()) {
                mActivity.doCancel(mAdapter);
            } else {
                mActivity.statisticsBack();
                mActivity.finish();
            }
        } else {
            mActivity.statisticsBack();
            mActivity.finish();
        }
    }

    @Override
    public void onShareClick(View v) {
        initShareImageView();
        initShareImageViewAdapter(mActivity.getCheckedImageNum(), mActivity.getCheckedVideoNum());
    }

    @Override
    public void onDeleteClick(View v) {
        showDeleteConfirmDialog();
    }

    @Override
    public int getImageNum() {
        return mUris.size();
    }

    private View getEmptyGalleryView() {
        if (mEmptyGalleryView == null) {
            ViewStub vs = (ViewStub) mContainerView.findViewById(R.id.empty_gallery_viewstub_id);
            if (vs != null) {
                mEmptyGalleryView = vs.inflate();
            } else {
                mEmptyGalleryView = mContainerView.findViewById(R.id.empty_gallery_layout_id);
            }
            if (mEmptyGalleryView != null) {
                TextView title = (TextView) mEmptyGalleryView.findViewById(R.id.empty_title);
                TextView content = (TextView) mEmptyGalleryView.findViewById(R.id.empty_content);
                View bt = mEmptyGalleryView.findViewById(R.id.empty_bt);
                title.setText(R.string.gallery_empty_title);
                content.setText(R.string.gallery_empty_content);
                bt.setVisibility(View.VISIBLE);
                bt.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        //TODO:调用系统相机
//						Intent intent = new Intent(mActivity, MainActivity.class);
//						intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
//								| Intent.FLAG_ACTIVITY_SINGLE_TOP
//								| Intent.FLAG_ACTIVITY_CLEAR_TOP);
//						intent.putExtra(ActionConstant.Extras.EXTRA_PAGE, MainActivity.PAGE_CAMERA);
//						mActivity.startActivity(intent);
                    }
                });
            }
        }
        return mEmptyGalleryView;
    }

    /**
     * 切tab时需要执行
     */
    public void setShareViewGone() {
        if (mShade != null && mShade.getVisibility() == View.VISIBLE) {
            if (mSharePanel != null) {
                mSharePanel.setVisibility(View.GONE);
            }
            if (mShade != null) {
                mShade.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 隐藏进度的Dialog
     */
    private void dismissProgressDialog() {
        try {
            if (mProgressDialog.isShowing()) {
                mProgressDialog.dismiss();
            }
        } catch (Throwable e) {
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        destoryGridFlowAd();
        cancelRequest();
    }

    private void cancelRequest() {
        if (mAdapter != null) {
            mAdapter.cancelCall();
        }
    }


    private void loadGridFlowAd() {

    }

    private void destoryGridFlowAd() {

    }

    public void takePhotoBack(ThumbnailBean thumbnailBean) {
        if (mActivity == null) {
            return;
        }
        //goto image edit
        mAdapter.gotoImageEditActivity(new GalleryRowItem(mActivity, 3), thumbnailBean, 0);
        mActivity.setNeedExitPageAd(false);
    }

}
